package biz.yfsoft.app.fastframework.config;

import java.text.MessageFormat;

import biz.yfsoft.app.fastframework.config.route.AdminRoutes;
import biz.yfsoft.app.fastframework.config.route.ThemeRoutes;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

public class Config extends JFinalConfig {
	
	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("config.txt");
		me.setViewType(ViewType.JSP);
		me.setBaseViewPath(getProperty("baseViewPath","/"));
		me.setDevMode(getPropertyToBoolean("devMode", false));
	}
	
	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		me.add(new ThemeRoutes());
		me.add(new AdminRoutes());
	}
	
	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		String host =  getProperty("db.host");
		String port =  getProperty("db.port");
		String name =  getProperty("db.name");
		String url = getProperty("db.url");
		url = MessageFormat.format(url, host,port,name);
		C3p0Plugin c3p0Plugin = new C3p0Plugin(url, getProperty("db.user"), getProperty("db.pass").trim());
		me.add(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
	}
	
	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {
		
	}
	
	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		
	}
}